<?php
class picture_topic_locale_concept extends system_concept_abstract {
	
	public function init() {
		$this->setModel('picture_topic_locale_model', 'locale');
		$this->setModelCols('locale', array('topic_id', 'lang', 'stotal', 'title', 'theme', 'description'));
	}

	public function save($row) {
		$row->set('topic_id', intval($row->get('topic_id')));
		if(!$row->getTopicId()) {
			throw new picture_exception("Topic ID can not be empty.");
		}
		if(!system_setting_language::verify($row->getLang())) {
			throw new picture_exception("Language(TOPIC-LOCAL) formation error.");
		}
		if(!$row->getTitle()) {
			throw new picture_exception("Title can not be empty.");
		}
		$scc = new picture_special_topic_concept($row->getLang());
		$row->setStotal($scc->fetchCount(array('topic_id = ?' => $row->getTopicId())));
		if(!$this->fetch(array('topic_id = ?' => $row->getTopicId(), 'lang = ?' => $row->getLang()))) {
			$this->getModel('locale')->insert($row->getModelData('locale'));
		} else {
			$row->update();
		}
		return $row;
	}

}